<?php
class Admin_Model_Bill extends Zend_Db_Table{
	protected $_name = 'bill';
	protected $_primary = 'bill_id';
	/* Link tham khao : http://framework.zend.com/manual/en/zend.db.table.html */
	/* select demo */
	
	// them thong tin payment vao bill
	/*public function insertBill($data)
	{
		$adapter = $this->getDefaultAdapter();
		try {
			$adapter->beginTransaction();
			$adapter->insert('bill', $data);
			$id = $adapter->lastInsertId($this->_name,$this->_primary);
			$adapter->commit();
			
		}
		catch (Zend_Db_Table_Exception $e) {
			$adapter->rollBack();
			return -1;
		}
		return $id;
	}*/
	
	public function getLastestOrder($limit)
	{//co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/bill/route/getLastestOrder/limit/".$limit);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	
	public function getOrderByStatus($status)//
	{//co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/bill/route/getOrderByStatus/status/".$status);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	
	public function getAllOrders()//
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/bill/route/getAllOrders");
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	public function getOrderById($Bill_Id)//
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restGet("/bill/route/getOrderById/Bill_Id/".$Bill_Id);
		$return = json_decode(json_encode((array) simplexml_load_string($return->getBody())),1);
		
		for ($i=0;$i <count($return);$i++)
				$data[$i] = $return['row_'.$i];
				
		return $data;
	}
	public function getOrderDetailById($Bill_Id)//
	{// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/bill/route/getOrderDetailById/Bill_Id/".urlencode($Bill_Id));
		return $return->getBody();
	}
	public  function  cancelOrder($id)//
	{	// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/bill/route/cancelOrder/id/".urlencode($id));
		return $return->getBody();
	}
	
	public  function  updateOrder($id,$status)//
	{	// co dung
		$client = new Zend_Rest_Client(HTTP_SERVICE);
		$return = $client->restPut("/bill/route/updateOrder/id/".urlencode($id)."/status/".urlencode($status));
		return $return->getBody();
	}
}